/******************************************************************************
 * Name: X86TraceManager.h
 * Author: ZhengJuyu, zhengjuyu@gmail.com
 * Date: 2008/08/24
 * Revision history:
 *
 * Purpose:
 *     Do the basic optimization "trace linking" on basic block, on IA32
 * architecture 
 *
 *****************************************************************************/

#ifndef X86TRACEMANAGER_H
#define X86TRACEMANAGER_H

#include "crossbit/TraceManager.h"

namespace crossbit
{
		class X86TraceManager : public TraceManager
		{
				public:
						X86TraceManager( MemoryManager *mm );
						virtual ~X86TraceManager();

						virtual void directLinkTo( TBlock* preBlock, XTInt32 exit, TBlock* block);
						virtual void indirectLinkTo( TBlock* preBlock, XTInt32 exit, TBlock* block);
						virtual void linkSuperBlock( TBlock* former_tblock , TBlock* super_tblock); 

				private:
						virtual void fillPredictionCodeBlock( TBlock* block );

						virtual XTMemAddr allocatePredictionCodeBlock();


				private:

						/******************************************************************
						 * On IA32 arichtecture, the prediction code block contain 3 
						 * instructions:
						 *      lea   -0x40001000(%edx), %ecx    ; 6 bytes
						 *      jecxz match                      ; 2 bytes
						 *      jmp	  nextPrediction             ; 6 bytes
						 *
						 * align it to 16 bytes
						 ******************************************************************/
						static const XTInt32 PREDICTIONCODEBLOCKLEN = 32;

						XTInt8 sample[PREDICTIONCODEBLOCKLEN];
		};
}
#endif	//X86TRACEMANAGER_H
